#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qxtglobalshortcut.h"
#ifdef Q_OS_WIN32
#include <Windows.h>
#endif
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QxtGlobalShortcut *shortcut = new QxtGlobalShortcut(QKeySequence("shift+O"), this);
    QObject::connect(shortcut, &QxtGlobalShortcut::activated, this, [this](){
        activateWindow();
        setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
        raise();
#ifdef Q_OS_WIN32
        //windows必须加这个，不然windows10 会不起作用，具体参看activateWindow 函数的文档
        HWND hForgroundWnd = GetForegroundWindow();
        DWORD dwForeID = ::GetWindowThreadProcessId(hForgroundWnd, NULL);
        DWORD dwCurID = ::GetCurrentThreadId();

        ::AttachThreadInput(dwCurID, dwForeID, TRUE);
        ::SetForegroundWindow((HWND)winId());
        ::AttachThreadInput(dwCurID, dwForeID, FALSE);
#endif // MAC_OS
        ui->label->setText("test is ok!");
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}

